package top.jfunc.json.impl.parse;

import top.jfunc.json.Json;
import top.jfunc.json.impl.parse.tokenizer.ReaderChar;
import top.jfunc.json.impl.parse.tokenizer.TokenList;
import top.jfunc.json.impl.parse.tokenizer.Tokenizer;

import java.io.StringReader;

public class JSONParser {
    private Tokenizer tokenizer = new Tokenizer();

    private Parser parser = new Parser();

    /**
     * @see top.jfunc.json.Json
     * @see top.jfunc.json.JsonObject
     * @see top.jfunc.json.impl.JSONObject
     * @see top.jfunc.json.JsonArray
     * @see top.jfunc.json.impl.JSONArray
     */
    public Json fromJSON(String json) {
        ReaderChar charReader = new ReaderChar(new StringReader(json));
        TokenList tokens = tokenizer.getTokenStream(charReader);
        return parser.parse(tokens);
    }
}
